export class uiSimple extends cc.Component {
  static gameInstanceList: { [key: string]: cc.Node } = {}
  static _gamePanel: cc.Node = null
  /**获取屏幕比率 */
  static getViewRatio() {
    const frameWidth = cc.winSize.width
    const frameHeight = cc.winSize.height
    const desWidth = cc.view.getDesignResolutionSize().width / 2
    const desHeight = cc.view.getDesignResolutionSize().height / 2
    const widthRatio = desWidth / frameWidth
    let target = (desHeight / frameHeight) * frameWidth - frameWidth * widthRatio
    return -Math.ceil(target)
  }
  /**获取节点尺寸 */
  static getNodeSize(target: cc.Node): cc.Size {
    return target.getContentSize()
  }
  /**设置节点尺寸 */
  static setNodeSize(target: cc.Node, size: cc.Size) {
    target.setContentSize(size)
  }
  /**设置带wiget组件的节点位置 */
  static setPosition(node: cc.Node, pos: cc.Vec2) {
    const widget = node.getComponent(cc.Widget)
    if (widget) {
      node.setPosition(pos)
      widget.left = pos.x
      widget.right = -pos.x
      widget.top = -pos.y
      widget.bottom = pos.y
    }
  }
  /**设置带wiget组件的节点位置 */
  static setPositionAdd(node: cc.Node, x: number, y: number) {
    const postion = node.position
    const posX = postion.x + x
    const posY = postion.y + y
    node.setPosition(cc.v2(posX, posY))
  }
  static getActionTime(v1: cc.Vec2, v2: cc.Vec2, speed: number = 200) {
    const pos1 = new cc.Vec2(v1.x, v1.y)
    const pos2 = new cc.Vec2(v2.x, v2.y)
    const dis = cc.Vec2.distance(pos1, pos2)
    return dis / speed
  }
  static scaleSeqTo(node: cc.Node, time: number, scale: number): Array<cc.FiniteTimeAction> {
    const old = node.scale
    const action1 = cc.scaleTo(time, scale)
    const action2 = cc.scaleTo(time, old)
    return [action1, action2]
  }
}
